package com.googlecode.erebos.server;

import com.googlecode.erebos.Location;
import com.sun.sgs.app.AppContext;

import java.io.Serializable;
import java.math.BigDecimal;

/**
 * The MIT License
 * <p/>
 * Copyright (c) 2009 Malachi de AElfweald (malachid@gmail.com)
 * <p/>
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * <p/>
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * <p/>
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
public class LocationImpl
implements Location, Serializable
{
    /** The version of the serialized form of this class. */
    private static final long serialVersionUID = 1L;

    // @TODO This needs rewritten based on http://code.google.com/p/erebos/wiki/CoordinateSystem


    private BigDecimal longitude, latitude, altitude;

    /**
     * Defaults to the Prime Meridian at the Equator
     */
    public LocationImpl()
    {
        longitude = BigDecimal.ZERO;
        latitude = BigDecimal.ZERO;
        altitude = BigDecimal.ZERO;
    }

    /**
     * Angular measurement in degrees ranged from 0&#176; at the equator to 90&#176; for the North Pole
     * and -90&#176; for the South Pole.
     * @return longitude
     */
    public BigDecimal getLongitude() {
        return longitude;
    }

    public void setLongitude(BigDecimal longitude) {
        AppContext.getDataManager().markForUpdate(this);
        this.longitude = longitude;
    }

    /**
     * Angular measurement in degrees ranged from 0&#176; at the prime meridian to 180&#176; East
     * and -180&#176; West
     * @return latitude
     */
    public BigDecimal getLatitude() {
        return latitude;
    }

    public void setLatitude(BigDecimal latitude) {
        AppContext.getDataManager().markForUpdate(this);
        this.latitude = latitude;
    }

    /**
     * Height in +feet or Depth in -feet
     * @return altitude
     */
    public BigDecimal getAltitude() {
        return altitude;
    }

    public void setAltitude(BigDecimal altitude) {
        AppContext.getDataManager().markForUpdate(this);
        this.altitude = altitude;
    }
}
